package com.hand.hzero.api.controller.v1;

import com.hand.hzero.config.SwaggerTags;
import io.choerodon.swagger.annotation.Permission;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.hzero.boot.file.FileClient;
import org.hzero.core.util.Results;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;

/**
 * <p>
 *
 * </p>
 *
 * @author hand-wd
 */
@Api(tags = SwaggerTags.EXAMPLE)
@RestController("fileController.v1")
@RequestMapping("/v1/file")
public class FileController {
    @Resource
    private FileClient fileClient;

    @ApiOperation(value = "文件上传")
    @Permission(permissionLogin = true)
    @PostMapping("/upload")
    public ResponseEntity<String> upload(
            @RequestParam("organizationId") Long oId,
            @RequestParam("bucketName") String bucketName,
            @RequestParam("directory") String directory,
            @RequestPart("file") MultipartFile file
    ) {
        String s = fileClient.uploadFile(oId, bucketName, directory, file);
        return Results.success(s);
    }
}
